const fs = require('fs');
const path = require('path');

const SERVICES_DIR = path.join(__dirname, '../api/services');

// 解析请求并返回本地 JSON 数据
exports.service =(req, res) => {
    const { method, path: requestPath, query, fields, cookies, params } = req;
    console.log(`Request: ${method} ${requestPath}`, { query, fields, cookies, params });

    const jsonFilePath = path.join(SERVICES_DIR, requestPath + '.json');
    if (fs.existsSync(jsonFilePath)) {
        const data = fs.readFileSync(jsonFilePath, 'utf-8');
        return res.json(JSON.parse(data));
    }

    res.status(404).json({ error: 'Mock data not found' });
}